import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import leteuserchilren from '../views/leteuserchilren/index.js'

Vue.use(VueRouter)
console.log(...leteuserchilren);

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/leteuser',
    name: 'leteuser',
    redirect: '/leteuser/index',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: function () {
      return import(/* webpackChunkName: "about" */ '../views/leteuser.vue')
    },
    children:[...leteuserchilren]
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 进行路由拦截

router.beforeEach((to,from,next)=>{
  Vue.nextTick().then(()=>{ 
      if(to.path !== '/' && !localStorage.getItem('token')){
        next('/')
       }else{
         next()
       }
     
  })

})

export default router
